import java.util.Random;
import java.util.Scanner;

//
public class Test2 {
    public static void main12(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int n = in.nextInt();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (i == j || (i+j) == n - 1) {
                        System.out.print("*");
                    } else {
                        System.out.print(" ");
                    }
                }
                System.out.println("");
            }
        }
    }


    //获取一个数的二级制序列中所有的奇数位和偶数位，分别输出二进制序列
    //按右边为第一位 0111 偶数位：01  奇数位：11
    public static void main11(String[] args) {
        Scanner in = new Scanner(System.in);
        while (true) {
            System.out.print("请输入一个数：");
            int n = in.nextInt();

            //偶数位
            System.out.print("偶数：");
            for (int i = 31; i >= 1; i -= 2) {
                System.out.print((n >>> i) & 1);
            }

            System.out.println();

            //奇数位
            System.out.print("奇数：");
            for (int i = 30; i >= 0; i -= 2) {
                System.out.print((n >>> i) & 1);
            }

            System.out.println();
        }
    }

    //求出0~999999的所有”水仙花数“并输出
    //例如153, 1^3+5^3+3^3 = 153
    public static void main10(String[] args) {
        for (int i = 0; i <= 999999; i++) {
            int count = 0;//计算i的位数
            int tmp = i;
            while (tmp != 0) {
                count++;
                tmp /= 10;
            }
            tmp = i;
            int sum = 0;
            while (tmp != 0) {
                sum += Math.pow(tmp % 10, count);
                tmp /= 10;
            }
            if (i == sum) {
                System.out.println(i);
            }
        }
    }

    //输出乘法口诀表
    public static void main9(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(i+" x "+j+" = "+i*j+"  ");
            }
            System.out.println();
        }
    }

    //猜数字游戏
    public static void main8(String[] args) {
        Random random = new Random();
        int randNum = random.nextInt(100);//[0,100)
        //System.out.println(randNum);
        Scanner scan = new Scanner(System.in);

        while (true) {
            System.out.print("请输入要猜的数字：");
            int n = scan.nextInt();
            if(n > randNum) {
                System.out.println("猜大了");
            }else if(n < randNum) {
                System.out.println("猜小了");
            }else {
                System.out.println("猜对了"+randNum+"是正确的");
                break;
            }
        }
    }

    //给定两个数，求这两个数的最大公约数
    public static void main7(String[] args) {
        Scanner in = new Scanner(System.in);
        while (true) {
            System.out.print("a = ");
            int a = in.nextInt();
            System.out.print("b = ");
            int b = in.nextInt();

            while(b != 0) {
                int temp = a % b;
                a = b;
                b = temp;
            }
            System.out.println("最大公约数为："+a);
        }
    }

    //求一个整数，在内存当中存储时，二进制1的个数
    public static void main63(String[] args) {
        Scanner in = new Scanner(System.in);
        while (true) {
            System.out.print("请输入一个数：");
            int n = in.nextInt();
            int count = 0;

            //n & (n - 1) 会少一个1
            //0111 & 0110 = 0110
            //0110 & 0101 = 0100
            //0100 & 0011 = 0000

            while (n != 0) {
                n = n & (n - 1);
                count++;
            }

            System.out.println("二进制1的个数为："+count);
        }
    }

    public static void main62(String[] args) {
        Scanner in = new Scanner(System.in);
        while (true) {
            System.out.print("请输入一个数：");
            int n = in.nextInt();
            int count = 0;
            //将n无符号右移，为零时，提前结束减少计算
            while (n != 0) {
                if ((n & 1) != 0) {
                    count++;
                }
                n >>>= 1;//n无符号右移
            }
            System.out.println("二进制1的个数为："+count);
        }
    }


    //移位可计算负数
    public static void main61(String[] args) {
        Scanner in = new Scanner(System.in);
        while (true) {
            System.out.print("请输入一个数：");
            int n = in.nextInt();
            int count = 0;
            for (int i = 0; i < 32; i++) {
                if (((n >>> i) & 1) != 0) {
                    count++;
                }
            }
            System.out.println("二进制1的个数为："+count);

        }
    }

    //不能计算负数
    public static void main6(String[] args) {
        Scanner in = new Scanner(System.in);
        while (true) {
            System.out.print("请输入一个整数：");
            int n = in.nextInt();
            int count = 0;
            while (n != 0) {
                if (n % 2 == 1) {
                    count++;
                }
                n /= 2;
            }
            System.out.println("二进制1的个数为："+count);
        }
    }

    //给定一个数字，判定一个数字是否是素数
    public static void main5(String[] args) {
        Scanner in = new Scanner(System.in);
        while (true) {
            System.out.print("请输入一个数：");
            int n = in.nextInt();
            int i = 2;
            for (; i <= Math.sqrt(n); i++) {
                if (n % i == 0) {
                    break;
                }
            }
            if (i > Math.sqrt(n)) {
                System.out.println(n+"是素数");
            } else {
                System.out.println(n+"不是素数");
            }
        }
    }

    public static void main4(String[] args) {
        Scanner in = new Scanner(System.in);
        while (true) {
            System.out.print("请输入一个数：");
            int n = in.nextInt();
            int i = 2;
            for (; i <= n/2; i++) {
                if (n % i == 0) {
                    break;
                }
            }
            if (i > n/2) {
                System.out.println(n+"是素数");
            } else {
                System.out.println(n+"不是素数");
            }
        }
    }

    //输出 1000 - 2000 之间所有的闰年
    public static void main3(String[] args) {
        for (int i = 1000; i <= 2000; i++) {
            if((i % 400 == 0) || (i % 100 != 0 && i % 4 == 0))
            {
                System.out.println(i);
            }
        }
    }

    //编写程序数一下 1到 100 的所有整数中出现多少个数字9
    public static void main2(String[] args) {
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            int temp = i;
            while (temp != 0) {
                if (temp % 10 == 9){
                    count++;
                }
                temp /= 10;
            }
        }
        System.out.println("1到100的所有整数中出现"+count+"个数字9");
    }

    //打印素数
    public static void main1(String[] args) {
        for (int i = 2; i <= 100; i++) {
            int j = 2;
            for (; j <= Math.sqrt(i); j++) {
                if (i % j == 0) {
                    break;
                }
            }
            if (j > Math.sqrt(i)){
                System.out.println(i);
            }
        }
    }
}
